package com.gaff.emp.core.util;

import cn.hutool.core.util.StrUtil;

import java.net.URLEncoder;
import java.util.Map;

public class HttpUtil {

    public static String appendParamToUrl(String url, Map<String, String> map) {
        if (map == null || map.isEmpty()) {
            return url;
        }
        StringBuffer buffer = new StringBuffer();
        for (Map.Entry<String, String> entry : map.entrySet()) {
            if (StrUtil.isEmpty(buffer.toString())) {
                buffer.append("?");
            } else {
                buffer.append("&");
            }
            buffer.append(entry.getKey()).append("=").append(URLEncoder.encode(entry.getValue()));
        }
        return url + buffer.toString();
    }

}
